Fork me on GitHub

使用Sysbench进行CPU、 内存、 IO 、线程、 mutex压力测试

本文主要介绍了如何使用Sysbench进行CPU、 内存、 IO 、线程、 mutex压力测试。

CPU测试

sysbench cpu help

1
2
3
4
5
sysbench cpu help
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000] 最大质数发生器数量。默认是10000

测试结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
➜ ~ sysbench cpu --cpu-max-prime=2000 run
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 2000
Initializing worker threads...
Threads started!
General statistics:
total time: 10.0001s
total number of events: 73827
Latency (ms):
min: 0.12
avg: 0.13
max: 5.69
95th percentile: 0.19
sum: 9961.81
Threads fairness:
events (avg/stddev): 73827.0000/0.00
execution time (avg/stddev): 9.9618/0.00

内存测试

1
2
3
4
5
6
7
8
9
sysbench memory help
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
memory options:
--memory-block-size=SIZE size of memory block for test [1K] 测试时内存块大小。默认是1K
--memory-total-size=SIZE total size of data to transfer [100G] 传输数据的总大小。默认是100G
--memory-scope=STRING memory access scope {global,local} [global] 内存访问范围{global,local}。默认是global
--memory-oper=STRING type of memory operations {read, write, none} [write] 内存操作类型。{read, write, none} 默认是write
--memory-access-mode=STRING memory access mode {seq,rnd} [seq] 存储器存取方式{seq,rnd} 默认是seq

测试结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
sysbench memory --memory-block-size=8k --memory-total-size=1G run
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 8KiB
total size: 1024MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 131072 (940750.90 per second)
1024.00 MiB transferred (7349.62 MiB/sec)
General statistics:
total time: 0.1369s
total number of events: 131072
Latency (ms):
min: 0.00
avg: 0.00
max: 1.18
95th percentile: 0.00
sum: 100.88
Threads fairness:
events (avg/stddev): 131072.0000/0.00
execution time (avg/stddev): 0.1009/0.00

I/O测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sysbench fileio help
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
fileio options:
--file-num=N number of files to create [128] 创建测试文件的数量。默认是128
--file-block-size=N block size to use in all IO operations [16384] 测试时文件块的大小。默认是16384(16K)
--file-total-size=SIZE total size of files to create [2G] 测试文件的总大小。默认是2G
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw} 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync] 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} [] 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100] 执行fsync()的频率。(0 – 不使用fsync())。默认是100
--file-fsync-all[=on|off] do fsync() after each write operation [off] 每执行完一次写操作就执行一次fsync。默认是off
--file-fsync-end[=on|off] do fsync() at the end of test [on] 在测试结束时才执行fsync。默认是on
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0
--file-rw-ratio=N reads/writes ratio for combined test [1.5] 测试时的读写比例。默认是1.5

1,prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。

1
sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare

2,run阶段

1
sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw run

3,清理测试时生成的文件

1
sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup

执行过程如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
128 files, 16384Kb each, 2048Mb total
Creating files for the test...
Extra file open flags: 0
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
Creating file test_file.6
Creating file test_file.7
Creating file test_file.8
Creating file test_file.9
Creating file test_file.10
Creating file test_file.11
Creating file test_file.12
Creating file test_file.13
Creating file test_file.14
Creating file test_file.15
Creating file test_file.16
Creating file test_file.17
Creating file test_file.18
Creating file test_file.19
Creating file test_file.20
Creating file test_file.21
Creating file test_file.22
Creating file test_file.23
Creating file test_file.24
Creating file test_file.25
Creating file test_file.26
Creating file test_file.27
Creating file test_file.28
Creating file test_file.29
Creating file test_file.30
Creating file test_file.31
Creating file test_file.32
Creating file test_file.33
Creating file test_file.34
Creating file test_file.35
Creating file test_file.36
Creating file test_file.37
Creating file test_file.38
Creating file test_file.39
Creating file test_file.40
Creating file test_file.41
Creating file test_file.42
Creating file test_file.43
Creating file test_file.44
Creating file test_file.45
Creating file test_file.46
Creating file test_file.47
Creating file test_file.48
Creating file test_file.49
Creating file test_file.50
Creating file test_file.51
Creating file test_file.52
Creating file test_file.53
Creating file test_file.54
Creating file test_file.55
Creating file test_file.56
Creating file test_file.57
Creating file test_file.58
Creating file test_file.59
Creating file test_file.60
Creating file test_file.61
Creating file test_file.62
Creating file test_file.63
Creating file test_file.64
Creating file test_file.65
Creating file test_file.66
Creating file test_file.67
Creating file test_file.68
Creating file test_file.69
Creating file test_file.70
Creating file test_file.71
Creating file test_file.72
Creating file test_file.73
Creating file test_file.74
Creating file test_file.75
Creating file test_file.76
Creating file test_file.77
Creating file test_file.78
Creating file test_file.79
Creating file test_file.80
Creating file test_file.81
Creating file test_file.82
Creating file test_file.83
Creating file test_file.84
Creating file test_file.85
Creating file test_file.86
Creating file test_file.87
Creating file test_file.88
Creating file test_file.89
Creating file test_file.90
Creating file test_file.91
Creating file test_file.92
Creating file test_file.93
Creating file test_file.94
Creating file test_file.95
Creating file test_file.96
Creating file test_file.97
Creating file test_file.98
Creating file test_file.99
Creating file test_file.100
Creating file test_file.101
Creating file test_file.102
Creating file test_file.103
Creating file test_file.104
Creating file test_file.105
Creating file test_file.106
Creating file test_file.107
Creating file test_file.108
Creating file test_file.109
Creating file test_file.110
Creating file test_file.111
Creating file test_file.112
Creating file test_file.113
Creating file test_file.114
Creating file test_file.115
Creating file test_file.116
Creating file test_file.117
Creating file test_file.118
Creating file test_file.119
Creating file test_file.120
Creating file test_file.121
Creating file test_file.122
Creating file test_file.123
Creating file test_file.124
Creating file test_file.125
Creating file test_file.126
Creating file test_file.127
2147483648 bytes written in 2.48 seconds (826.62 MiB/sec).
➜ ~
➜ ~
➜ ~ sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw run
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 20
Initializing random number generator from current time
Extra file open flags: 0
128 files, 16MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
reads/s: 15512.76
writes/s: 10341.51
fsyncs/s: 33093.17
Throughput:
read, MiB/s: 242.39
written, MiB/s: 161.59
General statistics:
total time: 10.0005s
total number of events: 589605
Latency (ms):
min: 0.00
avg: 0.22
max: 6.39
95th percentile: 0.50
sum: 130617.03
Threads fairness:
events (avg/stddev): 29480.2500/81.36
execution time (avg/stddev): 6.5309/0.01
➜ ~ sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Removing test files...

线程测试

1
2
3
4
5
6
sysbench threads help
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
threads options:
--thread-yields=N number of yields to do per request [1000] 每个请求产生多少个线程。默认是1000
--thread-locks=N number of locks per thread [8] 每个线程的锁的数量。默认是8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sysbench threads --num-threads=500 --thread-yields=100 --thread-locks=4 run
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 500
Initializing random number generator from current time
Initializing worker threads...
Threads started!
General statistics:
total time: 10.0902s
total number of events: 25095
Latency (ms):
min: 78.56
avg: 200.33
max: 258.32
95th percentile: 235.74
sum: 5027387.63
Threads fairness:
events (avg/stddev): 50.1900/0.40
execution time (avg/stddev): 10.0548/0.02

mutex测试

1
2
3
4
5
6
7
sysbench mutex help
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
mutex options:
--mutex-num=N total size of mutex array [4096] 数组互斥的总大小。默认是4096
--mutex-locks=N number of mutex locks to do per thread [50000] 每个线程互斥锁的数量。默认是50000
--mutex-loops=N number of empty loops to do outside mutex lock [10000] 内部互斥锁的空循环数量。默认是10000

执行过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
sysbench mutex --num-threads=100 --mutex-num=1000 --mutex-locks=100000 --mutex-loops=10000 run
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 100
Initializing random number generator from current time
Initializing worker threads...
Threads started!
General statistics:
total time: 17.9762s
total number of events: 100
Latency (ms):
min: 15479.16
avg: 17200.68
max: 17910.48
95th percentile: 17752.80
sum: 1720067.67
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 17.2007/0.59

参考

sysbench 安装、使用和测试

https://github.com/akopytov/sysbench

好记性不如烂笔头,生命不息,学习不止!

分享